package com.hwadeefsc.springboot.service.impl;

import com.hwadeefsc.springboot.dao.AttendanceDao;
import com.hwadeefsc.springboot.entity.Attendance;
import com.hwadeefsc.springboot.service.AttendanceService;

import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * (Attendance)表服务实现类
 *
 * @author makejava
 * @since 2024-07-09 21:43:27
 */
@Service("attendanceService")
public class AttendanceServiceImpl implements AttendanceService {
    @Resource
    private AttendanceDao attendanceDao;

    /**
     * 通过ID查询单条数据
     *
     * @param AttendanceId 主键
     * @return 实例对象
     */
    @Override
    public Attendance queryById(Integer AttendanceId) {
        return this.attendanceDao.queryById(AttendanceId);
    }

    /**
     * 分页查询
     *
     * @param attendance 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<Attendance> queryByPage(Attendance attendance, PageRequest pageRequest) {
        long total = this.attendanceDao.count(attendance);
        return new PageImpl<>(this.attendanceDao.queryAllByLimit(attendance, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param attendance 实例对象
     * @return 实例对象
     */
    @Override
    public Attendance insert(Attendance attendance) {
        this.attendanceDao.insert(attendance);
        return attendance;
    }

    /**
     * 修改数据
     *
     * @param attendance 实例对象
     * @return 实例对象
     */
    @Override
    public Attendance update(Attendance attendance) {
        this.attendanceDao.update(attendance);
        return this.queryById(attendance.getAttendanceId());
    }

    /**
     * 通过主键删除数据
     *
     * @param Attendance 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer Attendance) {
        return this.attendanceDao.deleteById(Attendance) > 0;
    }

    @Override
    public List<Map<String, Object>> countByStudentname(Integer studentId) {
        return attendanceDao.countByStudentId(studentId);
    }

    @Override
    public List<Map<String, Object>> allattendByStudent(Integer studentId) {
        return attendanceDao.allattendByStudentId(studentId);
    }


}
